function [BinnedObjects] =  BinObjects(ObjectsByFrame,ON,imageDimensions,binSize)

binnedDimensions=round(imageDimensions/binSize);
BinnedObjects=cell(length(ObjectsByFrame),1);

for k=1:length(ObjectsByFrame)
    BinnedObjects{k}=cell(binnedDimensions(1),binnedDimensions(2));
    %CurrentObjects=ObjectsByFrame{k};
    [numOfObjects,ONprops]=size(ObjectsByFrame{k});
    %for n=1:length(ObjectsByFrame{k})
    for n=1:numOfObjects
        %Centroid=ObjectsByFrame{k}(n).Centroid;
        Centroid(1)=ObjectsByFrame{k}(n,ON.CentroidX);
        Centroid(2)=ObjectsByFrame{k}(n,ON.CentroidY);
        x = max(round(Centroid(1)/binSize),1);
        y = max(round(Centroid(2)/binSize),1);       
        %BinnedObjects{k}{x,y}(end+1) = ObjectsByFrame{k}(n).Number;
        BinnedObjects{k}{x,y}(end+1) = ObjectsByFrame{k}(n,ON.Number);
        
    end
end
        